package com.example.famhealing.init;

import com.example.famhealing.R;
import com.example.famhealing.R.layout;
import com.example.famhealing.R.menu;
import com.example.famhealing.init.KakaoLink;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class MainMenuActivity extends Activity {

	//	LinearLayout ani = null;
	//	LinearLayout off = null;
	//	LinearLayout on = null;
	//	Animation an = null;
	//
	//	 private LinearLayout.LayoutParams params;
	//	 private boolean chkAni = false;
	ViewFlipper mFlip;
	//	LinearLayout li;
	RelativeLayout rl;
	FrameLayout fl;
	ScrollView second;
	int cnt = 1;
	int flg = 0;
	ImageView fa = null;
	Button htalk;
	EditText edittalk;
	Button ok;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_menu);
//		mFlip = (ViewFlipper)findViewById(R.id.flip);
//		fl = (FrameLayout)findViewById(R.id.framelay);

		htalk = (Button)findViewById(R.id.healingtalk);
		htalk.setSingleLine(true);
		htalk.setEllipsize(TextUtils.TruncateAt.END);
		
		edittalk = (EditText)findViewById(R.id.editHealingtalk);
		edittalk.setFilters(new InputFilter[] {
				new InputFilter.LengthFilter(100)
		});
		ok = (Button)findViewById(R.id.ok);
	}

	public void onClick (View v) {
		Intent intent;

		switch (v.getId()) {
		case R.id.fa : case R.id.mo : case R.id.gf : case R.id.gm :
		case R.id.so : case R.id.da : case R.id.ma : case R.id.wo :
		case R.id.yb : case R.id.ob : case R.id.ys : case R.id.os :

//			if (cnt % 2 == 1) {
//				fl.setVisibility(v.VISIBLE);
//				mFlip.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.viewin));
//				mFlip.setVisibility(0);
//				mFlip.showNext();
//				cnt++;
//			} else {
//
//				mFlip.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.viewout));
//
//		    	mFlip.showNext();
//				new Handler().postDelayed(new Runnable()
//				{
//				    @Override
//				    public void run()
//				    {
//						fl.setVisibility(View.GONE);
//				    }
//				}, 900);
//				System.out.println("2");
////				rl.setVisibility(0);
////				second.setVisibility(2);
//				cnt++;
//			}
//
//			break;
		case R.id.ImageView01:
			intent = new Intent(this, com.example.famhealing.schedule.CalendarActivity.class);
			//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
//			finish();
			break;
		case R.id.calling:
			startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:555-4")));
			break;
		case R.id.kakaotalk:
			break;
		case R.id.healingtalk:
			new AlertDialog.Builder(this)
			.setItems(R.array.healingtalk, 
					new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					String[] healingtalk = getResources().getStringArray(R.array.healingtalk);
					if (healingtalk[which].equals("힐링톡 수정")) {
						String text = htalk.getText().toString();
						htalk.setVisibility(View.GONE);
						edittalk.setVisibility(View.VISIBLE);
						ok.setVisibility(View.VISIBLE);
						edittalk.setText(text);
						ok.setOnClickListener(new View.OnClickListener() {

							@Override
							public void onClick(View v) {
								String txt = edittalk.getText().toString();
								edittalk.setVisibility(View.GONE);
								ok.setVisibility(View.GONE);
								htalk.setVisibility(View.VISIBLE);
								htalk.setText(txt);
							}
						});

					} else if (healingtalk[which].equals("힐링톡 이동")) {

					}
				}
			})
			.setNegativeButton("취소", null)
			.show();
			break;
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main_menu, menu);
		return true;
	}

}
